// 云对象教程: https://uniapp.dcloud.net.cn/uniCloud/cloud-obj
// jsdoc语法提示教程：https://ask.dcloud.net.cn/docs/#//ask.dcloud.net.cn/article/129

module.exports = {
	_before: function () { // 通用预处理器

	},

	/**
	 * @permission public
	 */
	async add(params = {}) {
		const dbJQL = uniCloud.databaseForJQL({
			clientInfo: this.getClientInfo()
		});
		return await dbJQL.collection("pro-blog").add(params);
	},

	/**
	 * @permission public
	 */
	async list(params = {}) {
		const dbJQL = uniCloud.databaseForJQL({
			clientInfo: this.getClientInfo()
		});
		let blogTemp = dbJQL.collection("pro-blog").orderBy("publish_date", "desc").getTemp();
		let userTemp = dbJQL.collection("uni-id-users").orderBy("_id", "nickname").getTemp();
		return dbJQL.collection(blogTemp, userTemp).get();
	},

	/**
	 * @permission public
	 */
	async remove(id) {
		const dbJQL = uniCloud.databaseForJQL({
			clientInfo: this.getClientInfo()
		});
		return await dbJQL.collection("pro-blog").doc(id).remove();
	}
}